package server

import (
	"fmt"
	"hero/router"
	"net/http"
)

// Server 结构体用于封装服务器的配置和状态
type Server struct {
	Port int
}

// NewServer 创建一个新的服务器实例
func NewServer(port int) *Server {
	return &Server{
		Port: port,
	}
}

// Run 启动服务器并监听指定端口
func (s *Server) Run() error {

	routers := router.Reg()
	addr := fmt.Sprintf(":%d", s.Port)
	fmt.Printf("Server is running on http://localhost%s\n", addr)
	return http.ListenAndServe(addr, routers)
}
